# 收集所有 .cpp 文件
device_tree_gen_src_files_raw = run_command('find', 'src/device_tree/interface', '-name', '*.cpp', '-type', 'f').stdout().strip().split('\n')

# 过滤掉空字符串并转换为 meson 文件对象
device_tree_gen_src_files = []
foreach f : device_tree_gen_src_files_raw
  if f != ''
    device_tree_gen_src_files += files(f)
  endif
endforeach

device_tree_gen_lib = shared_library(
  'device_tree',
  device_tree_gen_src_files,
  name_prefix: 'lib',
  name_suffix: 'so',
  install: true,
  install_dir: lib_dir,
  include_directories: [include_directories('include')],
  dependencies: [libmcpp_deps],
)

device_tree_gen_dep = declare_dependency(
  include_directories: include_directories('include'),
  link_with: device_tree_gen_lib,
)

if build_tests and meson_build
  custom_target(
    'copy_dev_device_tree_gen',
    output: 'copy_dev_device_tree_gen',
    command: ['cp', device_tree_gen_lib.full_path(), lib_dir],
    depends: device_tree_gen_lib,
    build_by_default: true,
  )
endif